package uk.co.q3c.deplan.client.ui.view.auto;

import uk.co.q3c.deplan.client.domain.DomainObject;
import uk.co.q3c.deplan.client.domain.resource.PersistenceReferenceException;
import uk.co.q3c.deplan.client.domain.task.BaseTask;
import uk.co.q3c.deplan.client.ui.presenter.PresenterBase;
import uk.co.q3c.deplan.client.ui.view.Q3CoreView;

public class ProjectTaskPresenterBase extends PresenterBase {

	public ProjectTaskPresenterBase() {
		super();
		prepareLabels();
	}

	public void objectToView() throws PersistenceReferenceException {
		BaseTask AbstractTask = (BaseTask) getObjectInView();
		ProjectTaskView view = (ProjectTaskView) getView();
		view.setActualFinishWidgetDataValue(AbstractTask.getActualFinish());
		view.setActualStartWidgetDataValue(AbstractTask.getActualStart());
		view.setAssignedResourceKeyWidgetDataValue(AbstractTask.getAssignedResourceKey());
		view.setAssignedUnitsWidgetDataValue(AbstractTask.getAssignedUnits());
		view.setDiscardedWidgetDataValue(AbstractTask.getDiscarded());
		view.setDiscardedDateWidgetDataValue(AbstractTask.getDiscardedDate());
		view.setDurationWidgetDataValue(AbstractTask.getDuration());
		view.setFinishWidgetDataValue(AbstractTask.finish());
		view.setFixedDurationWidgetDataValue(AbstractTask.isFixedDuration());
		view.setKeyIdWidgetDataValue(AbstractTask.getKeyId());
		view.setNameWidgetDataValue(AbstractTask.getName());
		view.setParentTaskKeyWidgetDataValue(AbstractTask.getParentTaskKey());
		// view.setPredecessorsKeysWidgetDataValue(BaseTask.getPredecessorsKeys());
		view.setPriorityWidgetDataValue(AbstractTask.getPriority());
		view.setProfilesWidgetDataValue(AbstractTask.getProfiles());
		view.setSpecificationWidgetDataValue(AbstractTask.getSpecification());
		view.setStartRemainingWidgetDataValue(AbstractTask.getStartRemaining());
		// view.setSuccessorsKeysWidgetDataValue(BaseTask.getSuccessorsKeys());
		view.setTargetFinishDateWidgetDataValue(AbstractTask.getTargetFinishDate());
		view.setTargetStartDateWidgetDataValue(AbstractTask.getTargetStartDate());
		view.setTempIdWidgetDataValue(AbstractTask.getTempId());
		view.setValidWidgetDataValue(AbstractTask.isValid());
		view.setWorkAllocatedWidgetDataValue(AbstractTask.getWorkAllocated());
		view.setWorkDoneWidgetDataValue(AbstractTask.getWorkDone());
		view.setWorkRemainingWidgetDataValue(AbstractTask.getWorkRemaining());
	}

	public void prepareLabels() {
		ProjectTaskView view = (ProjectTaskView) getView();
		view.setActualFinishWidgetLabelText("actual plannedFinish");
		view.setActualStartWidgetLabelText("actual start");
		view.setAssignedResourceKeyWidgetLabelText("assigned resource");
		view.setAssignedUnitsWidgetLabelText("assigned units");
		view.setDiscardedWidgetLabelText("discarded");
		view.setDiscardedDateWidgetLabelText("discarded date");
		view.setDurationWidgetLabelText("duration");
		view.setFinishWidgetLabelText("plannedFinish");
		view.setFixedDurationWidgetLabelText("fixed duration");
		view.setKeyIdWidgetLabelText("id");
		view.setNameWidgetLabelText("name");
		view.setParentTaskKeyWidgetLabelText("parent task");
		view.setPredecessorsKeysWidgetLabelText("predecessors");
		view.setPriorityWidgetLabelText("priority");
		view.setProfilesWidgetLabelText("profiles");
		view.setSpecificationWidgetLabelText("specification");
		view.setStartRemainingWidgetLabelText("start remaining");
		view.setSuccessorsKeysWidgetLabelText("successors");
		view.setTargetFinishDateWidgetLabelText("target plannedFinish date");
		view.setTargetStartDateWidgetLabelText("target start date");
		view.setTempIdWidgetLabelText("temp id");
		view.setValidWidgetLabelText("valid");
		view.setWorkAllocatedWidgetLabelText("work allocated");
		view.setWorkDoneWidgetLabelText("work done");
		view.setWorkRemainingWidgetLabelText("work remaining");
	}

	public void viewToObject() throws PersistenceReferenceException {
		BaseTask AbstractTask = (BaseTask) getObjectInView();
		ProjectTaskView view = (ProjectTaskView) getView();
		AbstractTask.setActualFinish(view.getActualFinishWidgetDataValue());
		AbstractTask.setActualStart(view.getActualStartWidgetDataValue());
		AbstractTask.setAssignedResourceKey(view.getAssignedResourceKeyWidgetDataValue());
		AbstractTask.setAssignedUnits(view.getAssignedUnitsWidgetDataValue());
		// BaseTask.setDiscarded(view.getDiscardedWidgetDataValue());
		AbstractTask.setDiscardedDate(view.getDiscardedDateWidgetDataValue());
		AbstractTask.setDuration(view.getDurationWidgetDataValue());
		AbstractTask.setPlannedFinish(view.getFinishWidgetDataValue());
		AbstractTask.setFixedDuration(view.getFixedDurationWidgetDataValue());
		AbstractTask.setName(view.getNameWidgetDataValue());
		// BaseTask.setParentTaskKey(view.getParentTaskKeyWidgetDataValue());
		// BaseTask.setPredecessorsKeys(view.getPredecessorsKeysWidgetDataValue());
		AbstractTask.setPriority(view.getPriorityWidgetDataValue());
		AbstractTask.setProfiles(view.getProfilesWidgetDataValue());
		AbstractTask.setSpecification(view.getSpecificationWidgetDataValue());
		AbstractTask.setStartRemaining(view.getStartRemainingWidgetDataValue());
		// BaseTask.setSuccessorsKeys(view.getSuccessorsKeysWidgetDataValue());
		AbstractTask.setTargetFinishDate(view.getTargetFinishDateWidgetDataValue());
		AbstractTask.setTargetStartDate(view.getTargetStartDateWidgetDataValue());
		AbstractTask.setTempId(view.getTempIdWidgetDataValue());
		AbstractTask.setValid(view.getValidWidgetDataValue());
		AbstractTask.setWorkAllocated(view.getWorkAllocatedWidgetDataValue());
		AbstractTask.setWorkRemaining(view.getWorkRemainingWidgetDataValue());
	}

	@Override
	public void prepareMenus() {
		throw new RuntimeException("Not yet implemented");

	}

	@Override
	public void setView(Q3CoreView view) {
		throw new RuntimeException("Not yet implemented");

	}

	@Override
	public void setObjectInView(DomainObject dob) {
		throw new RuntimeException("Not yet implemented");

	}

}